/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import server.Server;

/**
 *
 * @author Reynald
 */
public class ClientWorker implements Runnable{
    Socket client = null;
    OutputStream socketOutputStream = null;
    String filepath;
    Statement stmt;
    ResultSet rs;
    
    public ClientWorker(Socket client, Connection con){
        this.client = client;
        try {
            this.stmt = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(ClientWorker.class.getName()).log(Level.SEVERE, null, ex);
        }
    }    
    
    @Override
    public void run() {
        try {
            socketOutputStream = client.getOutputStream();
        } catch (IOException ex) {
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        }
        util.Utilities u = new util.Utilities();
        while(true){
            String query = "SELECT * FROM user where username = marchy and password = pandapotan";
            try {
                rs = stmt.executeQuery(query);
            } catch (SQLException ex) {
                Logger.getLogger(ClientWorker.class.getName()).log(Level.SEVERE, null, ex);
            }
            u.SendFile(filepath, socketOutputStream);
        }
        
    }
    
}
